package com.path.planning.mapper;

import com.path.planning.entity.RoutingNetwork;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Delete;

import java.util.List;

/**
 * 路网数据批量操作Mapper
 */
@Mapper
public interface NetworkDataMapper {

    /**
     * 批量插入路网数据
     */
    @Insert("<script>" +
            "INSERT INTO ${tableName} (name, geom, length, source, target, source_point, target_point, created_at, updated_at) VALUES " +
            "<foreach collection='networks' item='network' separator=','>" +
            "(#{network.name}, #{network.geom}, #{network.length}, #{network.source}, #{network.target}, #{network.sourcePoint}, #{network.targetPoint}, NOW(), NOW())" +
            "</foreach>" +
            "</script>")
    int batchInsertNetworks(@Param("tableName") String tableName, @Param("networks") List<RoutingNetwork> networks);

    /**
     * 清空指定表的数据
     */
    @Delete("DELETE FROM ${tableName}")
    int deleteAll(@Param("tableName") String tableName);

    /**
     * 根据ID删除路网数据
     */
    @Delete("DELETE FROM ${tableName} WHERE id = #{id}")
    int deleteById(@Param("tableName") String tableName, @Param("id") Long id);

    /**
     * 根据ID列表批量删除路网数据
     */
    @Delete("<script>" +
            "DELETE FROM ${tableName} WHERE id IN " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    int deleteByIds(@Param("tableName") String tableName, @Param("ids") List<Long> ids);
}
